package customerEnter.Frame.JDBCDao.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import customerEnter.Frame.DaoDataTransmission.DaoFramePameTransmission;
import customerEnter.Frame.JDBCDao.Interface.DaoFrameUseTypeInterface;

/**
 * 类描述：動態代理
 * 
 * 类名称：FrameInvocationHandler
 * 
 * 创建人：dy
 * 
 * 创建时间：2017-7-9 上午11:12:20
 * 
 * @param <T>
 * @param <K>
 * 
 */
@SuppressWarnings({ "rawtypes" })
public class FrameInvocationHandler<T, K> implements InvocationHandler {
	// 目标对象
	private DaoFrameUseTypeInterface	daoFrameUseTypeInterface;
	DaoFramePameTransmission<T, K>		daoFramePameTransmission;

	public Object invokeProxyObject(DaoFrameUseTypeInterface daoFrameUseTypeInterface,
			DaoFramePameTransmission<T, K> daoFramePameTransmission) {
		this.daoFrameUseTypeInterface = daoFrameUseTypeInterface;
		this.daoFramePameTransmission = daoFramePameTransmission;

		return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), this.daoFrameUseTypeInterface
				.getClass().getInterfaces(), this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		// 执行目标方法对象
		Object result = method.invoke(daoFrameUseTypeInterface, args);
		// closeConn();
		// System.out.println("關閉數據庫鏈接");
		// 在目标方法执行之后简单打印一下
		return result;
	}

}
